package com.drop.action;

import com.drop.entity.User;
import com.drop.service.UserInformationService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@Controller
@ParentPackage("struts-default")
@Namespace("/info")
@Scope("prototype")
public class UserInfoAction extends ActionSupport{
	@Autowired
	UserInformationService userinfo;
	
	
	@Action(value = "show",results = {
			@Result(name="showuserinfo",location = "/WEB-INF/person/information.jsp")
	})
	public String showUserInfo()
	{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();
		String name = (String) request.getSession().getAttribute("name");
		User user=userinfo.getUserInfo(name);
		ActionContext.getContext().put("userinfo", user);
		return "showuserinfo";
	}
	@Action(value = "update",results = {
			@Result(name="updateuserinfo",location = "show",type="chain")
	})
	public String updateUserInfo()
	{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session=request.getSession();
		String name=request.getParameter("realname");
		String tel=request.getParameter("telephone");
		String name1 = (String) request.getSession().getAttribute("name");
		User user=userinfo.getUserInfo(name1);
		user.setName(name);
		user.setTel(tel);
		userinfo.updateUserInfo(user);
		return "updateuserinfo";
	}
	
	public String upLoadhead()
	{
		
		return "uploadhead";
	}
}
